﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Collections.ObjectModel;
using Medianamik.Core.Interfaces;

namespace Medianamik.Core
{
	/// <summary>
	/// SystemNode représente un Noeud dont le Type est connu et utilisé
	/// par Médianamik pour la gestion des Roles, Modules, Menus...
	/// </summary>
    public abstract class SystemNode<T> : NodeWrapper, ISystemNode where T : NodeWrapper, new()  
    {
        public SystemNode()
        {}
        
        private List<T> _parentsOfSameType;
        public ReadOnlyCollection<T> ParentsOfSameType
        {
            get
            {
                if (_parentsOfSameType == null)
                {
                    var nodes = NodeManager.GetParentNodes<T>(this.InnerNode , null, false, 0)
                        .Where(n=>n.NodeType.GetParentIds(true).Any(id=>id.Equals(this.SystemNodeTypeID )));
                    _parentsOfSameType = nodes.ToList();

                }
                return _parentsOfSameType.AsReadOnly();
            }
        }

        #region ISystemNode Members

        public abstract Guid SystemNodeTypeID { get; }

        #endregion

        
    }
}